<%--
  Created by IntelliJ IDEA.
  User: bin.liu
  Date: 2018/12/5
  Time: 11:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<jsp:include page="/pages/sysIndex/default.jsp"/>

<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-trophy"></i> 设备管理
            </div>
            <div class="box-tools pull-right">
                <input type="hidden" id="maintainOrderId" value="${maintainOrderId}"/>
                <input type="hidden" id="serial" value="${serial}"/>
                <a href="#" class="btn btn-default" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 查询</a>
            </div>
        </div>

        <div class="box-body">
            <form id="searchForm" action="<c:url value="/web/admin/facility/listJson.action"/>" method="post" class="form-inline hide" data-page-no="1" data-page-size="20" data-order-by="">
                <div class="form-group">
                    <label class="control-label">设备编号：</label>
                    <div class="control-inline">
                        <input type="text" id="searchCode" name="searchCode" value="" maxlength="64" class="form-control width-120">
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label">设备名称：</label>
                    <div class="control-inline">
                        <input type="text" id="likeName" name="likeName" value="" maxlength="64" class="form-control width-120">
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label">设备区域：</label>
                    <div class="control-inline">
                        <input type="text" id="areaName" name="areaName" value="" maxlength="64" class="form-control width-120">
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label">所属专业：</label>
                    <div class="control-inline">
                        <input type="text" id="rootCatName" name="rootCatName" value="" maxlength="64" class="form-control width-120">
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label">设备类型：</label>
                    <div class="control-inline">
                        <input type="text" id="facilityCatName" name="facilityCatName" value="" maxlength="64" class="form-control width-120">
                    </div>
                </div>

                <div class="form-group">
                    <button type="submit" class="btn btn-primary btn-sm">查询</button>
                    <button type="reset" class="btn btn-default btn-sm">重置</button>
                </div>
            </form>

            <table id="addFacilityGrid"></table>
            <div id="addFacilityGridPage"></div>
            <div class="box-footer">
                <div class="row">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i
                                class="fa fa-check"></i>
                            保 存
                        </button>&nbsp;

                        <button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="closeView()"><i
                                class="fa fa-times"></i> 关 闭
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $('#addFacilityGrid').dataGrid({
        searchForm: $("#searchForm"),
        showCheckbox: true,
        columnModel: [
            {header:'序列号', name:'serialNum', index:'serialNum', width:80, align:"center",sortable: false},
            {header:'名称', name:'name', index:'name', width:80, align:"center",sortable: false},
            {header:'编码', name:'code', index:'code', width:80, align:"center",sortable: false},
            {header:'生产厂家', name:'factory', index:'factory', width:80, align:"center",sortable: false},
            {header:'所属区域', name:'areaName', index:'area', width:80, align:"center",sortable: false},
            {header:'位置', name:'position', index:'position', width:80, align:"center",sortable: false},
            {header:'具体位置', name:'precisePosition', index:'precisePosition', width:80, align:"center",sortable: false},
            {header:'所属类型', name:'facilityCatName', index:'facilityCat', width:80, align:"center",sortable: false},
            {header:'出厂日期', name:'releaseDate', index:'releaseDate', width:80, align:"center",sortable: false},
            {header:'所属企业', name:'enterpriseName', index:'enterprise', width:80, align:"center",sortable: false}
        ],
        // 加载成功后执行事件
        ajaxSuccess: function(data){

        }
    });
    $("#btnSubmit").click(function () {
        var ids = $("#addFacilityGrid").jqGrid("getGridParam", "selarrrow");
        if(ids.length==0){
            js.showMessage("请选择要添加的设备");
            return false;
        }
        $.ajax({
            type: 'post',
            url: "<c:url value="/web/admin/maintainOrder/showFacility.action" />",
            data: {"facilityIds": JSON.stringify(ids),"maintainOrderId":$("#maintainOrderId").val(),"serial":$("#serial").val()},
            dataType: 'json',
            async: false,
            success: function (data) {
                js.showMessage(data.msg);
                closeView();
                parent.$("#facilityMaintainSnapDataGrid").jqGrid().setGridParam({datatype:'json'}).trigger('reloadGrid');

            },
            error: function () {
                js.showMessage("出错了，请联系管理员");
            }
        });

    })

    function closeView() {
        console.log("关闭");
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);

    }



</script>
